package com.hxd.otc.module.my.activity;

import android.graphics.Color;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.module.my.contract.CooperativeMerchantAccessContract;
import com.hxd.otc.module.my.presenter.CooperativeMerchantAccessPresenter;
import com.hxd.otc.widget.AutoSplitOnTvGlobalLayoutAdapter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/12/18 0018.
 * description ${合作商户接入}
 */
public class CooperativeMerchantAccessActivity extends BaseActivity<CooperativeMerchantAccessPresenter> implements CooperativeMerchantAccessContract.IView {
    @BindView(R.id.et_name)
    EditText mEtName;
    @BindView(R.id.et_phone)
    EditText mEtPhone;
    @BindView(R.id.et_contact_way)
    EditText mEtContactWay;
    @BindView(R.id.et_referrer)
    EditText mEtReferrer;
    @BindView(R.id.tv_submit_applications)
    TextView mTvSubmitApplications;
    @BindView(R.id.tv_desc_2)
    TextView mTvDesc12;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_cooperative_merchant_access;
    }

    @Override
    protected CooperativeMerchantAccessPresenter createPresenter() {
        return new CooperativeMerchantAccessPresenter(this);
    }

    @Override
    protected void initView() {
        mTvDesc12.getViewTreeObserver().addOnGlobalLayoutListener(new AutoSplitOnTvGlobalLayoutAdapter(mTvDesc12));

        Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(mToolbar);
        //使用CollapsingToolbarLayout必须把title设置到CollapsingToolbarLayout上，设置到Toolbar上则不会显示
        CollapsingToolbarLayout mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
        mCollapsingToolbarLayout.setTitle(getString(R.string.cooperative_merchant_access_apply));
        //通过CollapsingToolbarLayout修改字体颜色
        mCollapsingToolbarLayout.setCollapsedTitleGravity(Gravity.CENTER);
        mCollapsingToolbarLayout.setExpandedTitleColor(Color.WHITE);//设置还没收缩时状态下字体颜色
        mCollapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);//设置收缩后Toolbar上字体的颜色
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void initEvent() {
    }

    @OnClick({R.id.tv_submit_applications, R.id.iv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_submit_applications:
                onSubmitApplication();
                break;
            case R.id.iv_back:
                onBackPressed();
                break;
        }
    }

    private void onSubmitApplication() {
        String name = mEtName.getText().toString().trim();
        if (TextUtils.isEmpty(name)) {
            showToast(getString(R.string.please_enter_your_name));
            mEtName.requestFocus();
            return;
        }
        String phone = mEtPhone.getText().toString().trim();
        if (TextUtils.isEmpty(phone)) {
            showToast(getString(R.string.please_enter_your_mobile_phone_number));
            mEtPhone.requestFocus();
            return;
        }
        String contactWay = mEtContactWay.getText().toString().trim();
        String referrer = mEtReferrer.getText().toString().trim();

        mPresenter.onSubmitApplication(name, phone, contactWay, referrer);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
    }

    @Override
    public void onSubmitApplicationSuccess() {
        showToast(getString(R.string.cooperative_merchant_access_success));
        finish();
    }
}
